package com.yx.musicplayer.ui.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.yx.baselibrary.base.BaseLazyFragment;
import com.yx.baselibrary.eventbus.EventCenter;
import com.yx.baselibrary.utils.TLogUtil;
import com.yx.musicplayer.R;
import com.yx.musicplayer.util.MusicPlayerServiceUtil;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by yx on 2017/11/3 0003.
 */

public class PlayBarFragment extends BaseLazyFragment {
    @BindView(R.id.user_image)
    ImageView userImage;
    @BindView(R.id.tv_music_name)
    TextView tvMusicName;
    @BindView(R.id.tv_artist)
    TextView tvArtist;
    @BindView(R.id.iv_play)
    ImageView ivPlay;
    @BindView(R.id.iv_like)
    ImageView ivLike;
    private boolean isPlay = false;
    private boolean isLike = false;


    @Override
    protected void onFirstUserVisible() {

    }

    @Override
    protected void onUserVisible() {
        TLogUtil.e("PlayBarFragment", isLike + "");
    }

    @Override
    protected void onUserInvisible() {

    }

    @Override
    public void before(Bundle savedInstanceState) {

    }

    @Override
    public void initViewAndEvent() {
        updateState();
    }

    @Override
    public int getContentViewLayoutID() {
        return R.layout.fragment_paly_bar;
    }

    @Override
    public boolean isBindEventBusHere() {
        return false;
    }

    @Override
    public void onEventComming(EventCenter eventCenter) {

    }

    @Override
    public void initPresenter() {

    }

    @Override
    public View getLoadingTargetView() {
        return null;
    }

    @OnClick({R.id.iv_play, R.id.iv_like})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.iv_play:
                MusicPlayerServiceUtil.playOrPause();
                updateState();
                break;
            case R.id.iv_like:
                setIfLike();
                isLike = !isLike;
                break;
            default:
                break;
        }
    }

    private void updateState() {

        try {
            if (MusicPlayerServiceUtil.isPlaying()) {
                ivPlay.setImageResource(R.drawable.vector_drawable_stop_grey);
            } else {
                ivPlay.setImageResource(R.drawable.vector_drawable_play_grey);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void setIfLike() {
        if (isLike) {
            ivLike.setImageResource(R.drawable.vector_drawable_like_normal);
        } else {
            ivLike.setImageResource(R.drawable.vector_drawable_like_press);
        }
    }


}
